package com.example.demo.controller;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.example.demo.model.Teachingplan;
import com.example.demo.service.AdminService;



@Controller
public class AdminController {
   
	@Autowired
    private  AdminService adminservice;
   
    
    @RequestMapping("/")
	public String login() {
		return "thymeleaf/login";
	}
    
    @RequestMapping("index")
	public String index() {
		return "thymeleaf/index";
	}
    
    @RequestMapping("teachingplanpage")
    public String teachingplanpage(Model md){
    	List<Teachingplan> planlist= adminservice.selectAllTeachingPlan();
    	md.addAttribute("planlist", planlist);
    	return "thymeleaf/data-table";
    }
    
    @RequestMapping("uploadexclepage")
	public String exclefile() {
		return "thymeleaf/uploadexcle";
	}
    
    @RequestMapping("fileexcle")
	public String fileexcle(@RequestParam("file") MultipartFile file,Model model) throws Exception {
		String filename=file.getOriginalFilename();
		System.out.println("上传Excel");
		adminservice.insertExcel(filename, file);
		model.addAttribute("msg", "上传成功");
		return "forward:uploadexclepage";
	}
}
